import {Pipe, PipeTransform} from '@angular/core';

// const OrderStatusList = [
//   {id: '0', value: '有效'},
//   {id: '1', value: '无效'},
//   {id: '2', value: '待付款'},
//   {id: '3', value: '待审核'},
//   {id: '4', value: '审核不通过'},
//   {id: '5', value: '审核通过'},
//   {id: '6', value: '排队发货'},
//   {id: '7', value: '待发货'},
//   {id: '8', value: '待收货（已发货）'},
//   {id: '9', value: '交易完成'},
//   {id: '10', value: '支付超时'},
//   {id: '11', value: '客服取消'},
//   {id: '12', value: '客户取消'},
//   {id: '13', value: '售后中'},
//   {id: '14', value: '全部退货'}];
const OrderStatusList = [
  {id: '2', value: '待付款'},
  {id: '3', value: '待发货'},
  {id: '4', value: '待发货'},
  {id: '5', value: '待发货'},
  {id: '6', value: '待发货'},
  {id: '7', value: '待发货'},
  {id: '8', value: '待收货'},
  {id: '9', value: '交易完成'},
  {id: '10', value: '支付超时'},
  {id: '11', value: '客服取消'},
  {id: '12', value: '客户取消'},
  {id: '16', value: '交易结束'},
];

@Pipe({
  name: 'orderStatus'
})
export class OrderStatus implements PipeTransform {

  transform(value: any, ...args: unknown[]): unknown {
    const result = OrderStatusList.filter(item => item.id === value + '');
    return result.length ? result[0].value : '未知类型';
  }

}

// new (1：支付宝，2：财付通，3：敏付)
const payTypeArrs: Array<any> = [
  { value: '1', label: '支付宝' },
  { value: '2', label: '财付通' },
  { value: '3', label: '敏付' },
  { value: '999', label: '爱豆' }
];
@Pipe({
  name: 'payType'
})
export class PayType implements PipeTransform {

  transform(value: any, ...args: unknown[]): unknown {
    let result: any = [];

    if (value) {
      let tempArr = value.split(',');
      payTypeArrs.forEach((ele: any) => {
        if (tempArr.includes(ele.value)) {
          result.push(ele.label);
        }
      });
    }
    return result?.length ? result.join('、') : '-';
  }

}

@Pipe({
  name: 'payStatus'
})
export class PayStatus implements PipeTransform {

  transform(value: unknown, ...args: unknown[]): unknown {
    let result;
    switch (value + '') {
      case '0':
        result = '未支付';
        break;
      case '1':
        result = '已支付';
        break;
      case '2':
        result = '失败';
        break;
      case '3':
        result = '已关闭';
        break;
      default:
        result = '未知';
        break;
    }
    result = value ? result : '';
    return result;
  }

}

/**
 * 赠送标识：0-非赠品，1-赠品、2-红包兑换
 */
@Pipe({ name: 'giftFlag' })
export class GiftFlagPipe implements PipeTransform {
  transform(value: any) {
    switch (String(value)) {
      case '1':
        return '赠品';
      case '2':
        return '兑换';
      default: 
        return '-';
    }
  }
}
